//
//  TipAlertView.m
//  AAIM
//
//  Created by 远的小布丁 on 2019/12/2.
//  Copyright © 2019 AAIM. All rights reserved.
//

#import "TipAlertView.h"

@implementation TipAlertView

-(instancetype)initWithFrame:(CGRect)frame  withType:(NSString*)Type title:(NSString*)title
{
    
    if (self) {
        self=[super initWithFrame:frame];
        self.backgroundColor=[UIColor colorWithWhite:0 alpha:0.0];
        
        //        if ([Type isEqualToString:@"1"]) {
        
        [self createUIWithType:Type title:title];
        //        }else
        //        {
        //            //弹窗
        //
        //        }
        
    }

    return self;
}
-(void)createUIWithType:(NSString*)type title:(NSString*)title
{
    
    _hideView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    _hideView.backgroundColor= [UIColor blackColor];
    _hideView.alpha=0.6;
    [self addSubview:self.hideView];
    
    _backView=[[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight - 80.f ,SCALAE_WIDTH(225.f), 30.f)];
    _backView.backgroundColor=[UIColor whiteColor];
    _backView.layer.masksToBounds=YES;
    _backView.layer.cornerRadius=30.f/2;
    _backView.userInteractionEnabled=YES;
    _backView.centerX = self.centerX;
    [self addSubview:self.backView];
    
    _TopTitleLbl=[[UILabel alloc]initWithFrame:CGRectMake(0,0, _backView.width, _backView.height)];
    _TopTitleLbl.font=[UIFont boldSystemFontOfSize:15];
    _TopTitleLbl.textColor=KHEXCOLOR(@"#333333");
    _TopTitleLbl.textAlignment=1;
    [self.backView addSubview:self.TopTitleLbl];
 if ([type isEqualToString:@"1"]){
     
        _TopTitleLbl.font=[UIFont systemFontOfSize:15];
        _TopTitleLbl.textColor=KHEXCOLOR(kBlackColor);
        _TopTitleLbl.numberOfLines=0;
        _TopTitleLbl.text=title;
    }
    
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self removeAllSubviews];
            self.hidden = YES;
        });
    
}

-(void)clickButton:(UIButton*)sender
{
    if (sender.tag==1) {
        
        if (self.clickBlock) {
//            self.clickBlock(@"1",_textTF.text,_remarkTF.text);
        }
        
    }else
    {
        if (self.clickBlock) {
//            self.clickBlock(@"2",_textTF.text,_remarkTF.text);
        }
    }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self endEditing:YES];
}
@end
